package com.viettel.data;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import com.viettel.BO.PortalUserBean;

public class ApplyJobFetcher {
	private final String NAMESPACE = "http://webservice.viettel.com/";
	private final String METHOD_NAME = "submitApplyJob";
	private final String SOAP_ACTION = "http://webservice.viettel.com/submitApplyJob";
	private final String URL = "http://192.168.5.101:8084/RMSPortal/RMSWebService?wsdl";

	private SoapSerializationEnvelope envelope;

	public ApplyJobFetcher(String email, String recruitmentAnouncementId,
			String currentSalary, String disireSalary, String place) {

		SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

		// Tham so email
		PropertyInfo userNameProperty = new PropertyInfo();
		userNameProperty.setName("email");
		userNameProperty.setValue(email);
		userNameProperty.setType(String.class);
		request.addProperty(userNameProperty);

		// Tham so ID
		PropertyInfo recruitmentAnounceProperty = new PropertyInfo();
		recruitmentAnounceProperty.setName("recruitmentAnouncementId");
		recruitmentAnounceProperty.setValue(recruitmentAnouncementId);
		recruitmentAnounceProperty.setType(String.class);
		request.addProperty(recruitmentAnounceProperty);

		// Tham so muc luong hien tai
		PropertyInfo currentSalaryProperty = new PropertyInfo();
		currentSalaryProperty.setName("currentSalary");
		currentSalaryProperty.setValue(currentSalary);
		currentSalaryProperty.setType(String.class);
		request.addProperty(currentSalaryProperty);

		PropertyInfo disireSalaryProperty = new PropertyInfo();
		disireSalaryProperty.setName("disireSalary");
		disireSalaryProperty.setValue(disireSalary);
		disireSalaryProperty.setType(String.class);
		request.addProperty(disireSalaryProperty);

		PropertyInfo placeProperty = new PropertyInfo();
		placeProperty.setName("place");
		placeProperty.setValue(place);
		placeProperty.setType(Double.class);
		request.addProperty(placeProperty);

		envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.setOutputSoapObject(request);
	}

	/**
	 * Tra ve ket qua Apply
	 * 
	 * @return
	 * 
	 */
	public String getResultApply() {
		HttpTransportSE httpRequest = new HttpTransportSE(URL);
		String result = "02";
		try {
			httpRequest.call(SOAP_ACTION, envelope);
			SoapObject response2 = (SoapObject) envelope.bodyIn;
			int iToltalCount = response2.getPropertyCount();
			if (iToltalCount > 0) {
				SoapObject element;
				element = (SoapObject) response2.getProperty(0);
				result = element.toString();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return result;
	}

}
